<template>
  <div>
    <div class="app-container">
      <div>{{ message.model }}, {{ message.res_id }}</div>
      <mt-cell title="请查看" label="点击查看" @click.native="handleClick">
        .
      </mt-cell>
      <!-- <mt-cell v-for="line in lines" :key="line.id" :title="line.name">
        .
      </mt-cell> -->
    </div>
  </div>
</template>

<script>
import odoo from '@/odooapi'

export default {
  name: 'Message',
  components: {},
  directives: {},
  filters: {},
  mixins: [],

  props: {
    message: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },

  data() {
    return {
      //
      inputPath: '/app/consult/survey-input',
      order: '',
      lines: []
    }
  },
  computed: {
    //
  },

  watch: {
    //
  },

  async created() {
    //
    console.log(
      'xxx, msg,',
      this.message.id,
      this.message.model,
      this.message.res_id
    )

    if (this.message.model === 'sale.order') {
      const obj = odoo.env(this.message.model)
      const fields = {
        partner_id: {},
        user_id: { partner_id: null },
        name: null,
        date_order: null,
        state: null,
        invoice_status: null,
        order_line: {
          name: null,
          product_id: null,
          display_type: null
        }
      }
      // const res = await obj.browse_one(this.message.res_id, { fields })
      // this.order = res
      // this.lines = res.order_line__objects
      // console.log('xxxxx, order,', res)
    } else if (this.message.model === 'survey.survey') {
      const obj = odoo.env(this.message.model)
      const fields = {
        // question_ids: {
        //   question: null,
        //   title: null,
        //   description: null,
        //   question_type: null,
        //   labels_ids: {},
        //   matrix_subtype: null,
        //   labels_ids_2: null,
        //   user_input_line_ids: {}
        // }
      }
      const res = await obj.browse_one(this.message.res_id, { fields })
      // this.order = res
      // this.lines = res.order_line__objects
      console.log('xxxxx, survey,', res)
      //
    }
  },

  mounted() {
    //
  },

  methods: {
    async handleClick() {
      console.log(
        'xxx, msg,',
        this.message.id,
        this.message.model,
        this.message.res_id
      )

      if (this.message.model === 'consult.consultation') {
        const fields = {
          date: null,
          response_id: null
        }

        // 取得 当前的 咨询单
        const consultation = await this.$store.dispatch(
          'appConsultation/browse_one',
          {
            id: this.message.res_id,
            fields
          }
        )

        console.log('xx', consultation)
        // 跳转到 咨询单对应 调查问卷的 user input
        this.$router.push({
          path: this.inputPath,
          query: { id: consultation.response_id }
        })
      }
    }
  }
}
</script>

<style type="text/css"></style>
